  <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>系统</title>
        <jsp:include page="/views/include.jsp"></jsp:include>
        <script type="text/javascript">
        	var contextPath = '<%=request.getContextPath()%>';
        	$.parser.onComplete = function(){
            	$('body').css('visibility','visible');
            	setTimeout(function(){
	            	$('#loading-mask').remove();
            	},50);
        	};
        	$(function(){
            	$(window).resize(function(){
                	$('#mainlayout').layout('resize');
            	});
        	});
        </script>
	<script type="text/javascript">
	//----------------------格式化显示状态名称
		var advertype;
		var releasepattern;
		
		
		$.getJSON("<c:url value='/release/outDicJsonByNicknameRelease.tg?nickName=advertype'/>", function(json){
			advertype=json;
		});                              
		$.getJSON("<c:url value='/release/outDicJsonByNicknameRelease.tg?nickName=releasepattern'/>", function(json){
			releasepattern=json;
		});
		
		function statusFormatter(value){
			for(var i=0; i<advertype.length; i++){
				if (advertype[i].value == value) return advertype[i].name;
			}
			return value;
		}
		
	    function releaseFormatter(value){
	    	for(var i=0; i<releasepattern.length;i++){
	    		if(releasepattern[i].value == value) return releasepattern[i].name;
	    	}
	    	return value;
	    }	
	//------------------------------------
		$(function(){
			init();
			$('#dt-Release').datagrid({onDblClickRow:function dblClickRow(rowIndex,rowData){
			    //alert(rowIndex+"-"+JSON.stringify(rowData));
				//$('#detailform').form('load',rowData);
				//$('#detail').dialog('setTitle','更新角色信息').dialog('open');
				$.each($('#myform input'),function(i){
    					$(this).attr("readonly","true");
    				});
    				$("#dlg-buttons a:first-child").hide();
				$('#dlg').dialog('setTitle','查看广告信息').dialog('open');
			}});
		});
		function init(){
			$('#dlg').dialog({
				onOpen:function(){
					$('#dt-Release').datagrid('resize');
				}
			});
			
		}
		function advanceQuery(){
			showQueryDialog({
				width:350,
				height:300,
			    //form:'<c:url value="/views/advertising/releaseadvertising/_query.jsp"/>',
				callback:function(data){
					$('#dt-Release').datagrid('loadData', {total:0,rows:[]});
					$('#dt-Release').datagrid('load',data);
				}
			});
		}
		function back(){
			$('#dt-Release').datagrid('loadData', {total:0,rows:[]});
			$('#dt-Release').datagrid('load',{});
		}
		

		function approveItem(){
			var row = $('#dt-Release').datagrid('getSelected');
			if(row){
				url = '<c:url value="/release/updateRelease.tg"/>?';
				//row = JSON.stringify(row).replace(/\./g,"\\\\.");
				//$('#myform').form('load',eval('('+row+')'));
				$('#myform').formid('loadit',row);
				$.each($('#myform input'),function(i){
					$(this).removeAttr("readonly");
				});
				$("#dlg-buttons a:first-child").show();
				$('#dlg').dialog('setTitle','下发信息').dialog('open');
				
			}else {
				$.messager.show({
					title:'注意',
					msg:'请先选择数据，再进行下发操做。'
				});
			}
			
		
		}
		function editItem(){
			var row = $('#dt-Release').datagrid('getSelected');
			if (row){
				url = '<c:url value="/release/updateRelease.tg"/>?';
				//row = JSON.stringify(row).replace(/\./g,"\\\\.");
				//$('#myform').form('load',eval('('+row+')'));
				$('#myform').formid('loadit',row);
				$.each($('#myform input'),function(i){
					$(this).removeAttr("readonly");
				});
				$("#dlg-buttons a:first-child").show();
				$('#dlg').dialog('setTitle','更新信息').dialog('open');
			} else {
				$.messager.show({
					title:'注意',
					msg:'请先选择数据，再进行修改。'
				});
			}
		}
		function removeItem(){
			var row = $('#dt-Release').datagrid('getSelected');
			if (row){
				if(confirm('确定要删除？')){
					url = '<c:url value="/release/deleteRelease.tg"/>?id='+row["aid"];
					 $('#myform').form('submit',{
							url:url,
							onSubmit:function(){return true;},
							success:function(data){
								$('#dt-Release').datagrid('reload');
								data=eval('('+data+')');
								if(data.success){
									$.messager.show(
										{
											title:'提示',
											msg:'删除操作成功！',
											showType:'slide'
										}
									);
								}
								if(data.error){
									$.messager.alert('警告','删除操作失败！','error');
								}
							}
						});
				}
			} else {
				$.messager.show({
					title:'注意',
					msg:'请先选择信息，再进行删除。'
				});
			}
		}
		function saveItem(){
			var data = $('#myform').form('submit',{
				url:url,
				onSubmit:function(){return $(this).form('validate');},
				success:function(data){
					$('#dlg').dialog('close');
					$('#dt-Release').datagrid('reload');
					data=eval('('+data+')');
					if(data.success){
						$.messager.show(
							{
								title:'提示',
								msg:'保存操作成功！',
								showType:'slide'
							}
						);
					}
					if(data.error){
						$.messager.alert('警告','操作失败！','error');
					}
				}
			});
			
		}
		
	</script>